package com.project.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.controller.BaseController;
import com.project.dto.Result;
import com.project.dto.response.UserDTO;
import com.project.entity.User;
import com.project.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date : 10:24 2020/7/1
 */
@RestController
@Api(tags = "管理员")
public class AdminController extends BaseController {
    @Autowired
    private UserService userService;

    @ApiOperation("重置密码")
    @GetMapping("/admin/resetPwd")
    public Result resetPwd(Long userId) {
        userService.resetPwd(userId);
        return success();
    }

    @ApiOperation("获取用户列表")
    @GetMapping(value = "/admin/list")
    public Result<IPage<UserDTO>> list(String username,
                                       @RequestParam(defaultValue = "1") Long page,
                                       @RequestParam(defaultValue = "10") Long pageSize) {
        IPage<User> userIPage = userService.selectPageUserList(page, pageSize,username);
        return success(userIPage,UserDTO.class);
    }

    @ApiOperation("删除用户")
    @GetMapping(value = "/user/delete")
    public Result delete(@RequestParam Long id) {
        userService.deleteById(id);
        return success();
    }
}
